package org.example.Controller;

import lombok.extern.slf4j.Slf4j;
import org.example.Pojo.Result;
import org.example.Utils.AliyunOSSOperator;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.multipart.MultipartFile;

@Slf4j
@RestController
public class UploadController {

    @Autowired
    AliyunOSSOperator aliyunOSSOperator;

    @PostMapping("/upload")
    public Result upload(@RequestParam("file") MultipartFile file,Integer age,String username) throws Exception {
        log.info("age:{},username:{}", age,username);
        if(!file.isEmpty()) {
            String url= aliyunOSSOperator.upload(file.getBytes(),file.getOriginalFilename());
            return Result.success(url);
        }
        return Result.success();
    }
}
